<?php
$group_id=$_GET['group_id'];
$id=$_GET['id'];
if(isset($_POST['submit']))
{
	if($_POST['submit']=='Lưu' || $_POST['submit']=='Lưu & Đóng')
	{
		$page_name=Page::save_page_content_by_id($id,$_POST['page_content'],$_POST['page_title'],$_POST['page_quote']);
		if($_POST['submit']=='Lưu & Đóng')
			Common::header_location(null,null,"$('#btn_close').trigger('click')");
	}
	else if($_POST['submit']=='Xóa')
	{
		Db::mysql_query("DELETE FROM tbl_page WHERE page_id='$id' ",FETCH_MODE_NONE);
		Common::header_location('Xóa thành công!','index.php?page='.($group_id==3?'tin-tuc':'lop-day-hien-co'));
	}
}
$array=Page::fetch_page_by_id($id);
$page_status=$array['page_status'];
$page_content=$array['page_content'];
$page_type=$array['page_type']; 
$page_title=$array['page_title'];
$page_quote=$array['page_quote_'.$language];
if($page_status==0)
	$page_quote=PAGE_QUOTE;
?>

<script type="text/javascript" src="<?php echo BASE_URL?>ext/js/ckeditor/ckeditor.js" ></script>
<script>
	$(document).ready(function(){
		var ckfinder_url='<? echo BASE_URL?>ext/js/ckfinder/';
		$(".editor").each(function(){				
			CKEDITOR.replace(this, { 
			height:'200px'
			, width:'780px'
			,toolbar:'Full'					
			,filebrowserBrowseUrl:ckfinder_url+'ckfinder.html'
			,filebrowserImageBrowseUrl:ckfinder_url+'ckfinder.html?type=images'
			,filebrowserFlashBrowseUrl:ckfinder_url+'ckfinder.html?type=flash'
			,filebrowserUploadUrl:ckfinder_url+'core/connector/php/connector.php?command=QuickUpload&type=files'
			,filebrowserImageUploadUrl:ckfinder_url+'core/connector/php/connector.php?command=QuickUpload&type=images'
			,filebrowserFlashUploadUrl:ckfinder_url+'core/connector/php/connector.php?command=QuickUpload&type=flash'
			});			
		});		
	})
	function checkForm()
	{
		if($('#page_title').val()=='')
		{
			alert('Vui lòng điền tiêu đề!');
			$('#page_title').focus();
			return false;
		}
	}
</script>

<style>
	.editor{ width:788px;height:200px}
</style>

<form method='post' onsubmit='return checkForm()'>
	Tiêu đề<br/>
	<input size='50' type='text' id='page_title' name='page_title' value='<?php echo $page_title;?>' /><br/>
	Trích dẫn<br/>
	<textarea name='page_quote' class='editor'><?php echo $page_quote;?></textarea><br/>
	Nội dung<br/>
	<textarea name='page_content' class='editor'><?php echo $page_content;?></textarea><br/>
	<div style='text-align:right;padding:4px'>
		<input type='submit' value='Xóa' name='submit' onclick="if(!confirm('Bạn có đồng ý xóa?')) return false;"/>
		<input type='submit' value='Lưu' name='submit'/>
		<input type='submit' value='Lưu & Đóng' name='submit'/>
		<input type='button' value='Đóng' id='btn_close' onclick="
			if(window.opener)
			{
				window.opener.location.reload();
				window.close();
			}
			else 
			{
				window.location='index.php?page=<?php echo $group_id==3?'tin-tuc':'lop-day-hien-co'?>';	
			}
		"/>
	</div>
</form>